package cn.edu.zsc.blms.domain;
import cn.edu.zsc.blms.util.DateUtil;

import java.util.Date;
import java.util.Objects;

public class Book extends BaseEntity{
    public static int idCounter = 0;
    public String name;
    public String isbn;
    public String category;
    public String author;
    public String press;
    public Double price;
    public boolean disabled;
    public Date publishDate;
    public enum Status{
        可出借,
        已借出
    }
    public Status status = Status.可出借;
    public Book(){
        this.id = idCounter++;
        this.name = "null";
        this.isbn = "null";
        this.category = "null";
        this.author = "null";
        this.press = "null";
        this.price = 0.0;
        this.disabled = false;
    }
    public Book(String name, String isbn, String category, String author, String press,Date publishDate,Double price){
        this();
        this.name = name;
        this.isbn = isbn;
        this.category = category;
        this.author = author;
        this.press = press;
        this.price = price;
        this.publishDate = publishDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        Book book = (Book) o;
        return disabled == book.disabled && Objects.equals(name, book.name) && Objects.equals(isbn, book.isbn) && Objects.equals(category, book.category) && Objects.equals(author, book.author) && Objects.equals(press, book.press) && Objects.equals(price, book.price) && Objects.equals(publishDate, book.publishDate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), name, isbn, category, author, press, price, disabled, publishDate);
    }

    @Override
    public String toString() {
        return "ID: " + id + ", 书名: " + name + ", isbn: " + isbn + ", 类目: " + category + ", 作者: " + author + "， 出版社: " + press + "， 出版日期: " + DateUtil.formatDate(publishDate) + ", 价格: " + price + ", 废弃: " + (disabled ? "是" : "否") + ", 状态: " + status;
    }
}
